package com.jiangyg.mall.order.controller;

import com.jiangyg.mall.core.support.restful.Pagination;
import com.jiangyg.mall.core.support.restful.Result;
import com.jiangyg.mall.order.dto.OrderReturnReasonDTO;
import com.jiangyg.mall.order.service.OrderReturnReasonService;
import com.jiangyg.mall.order.vo.OrderReturnReasonVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 类描述：退货原因控制器
 *
 * @author jiangyg
 * @version email@jiangyg.com
 * @date 2021-10-30 07:36:29
 */
@RestController
@RequestMapping("/order/orderReturnReason")
public class OrderReturnReasonController {

    /**
     * 退货原因接口
     */
    private final OrderReturnReasonService orderReturnReasonService;

    @Autowired
    public OrderReturnReasonController(OrderReturnReasonService orderReturnReasonService) {
        this.orderReturnReasonService = orderReturnReasonService;
    }

    /**
     * 功能描述：退货原因分页查询
     *
     * @param request    请求
     * @param pagination 分页参数
     * @return 返回分页退货原因
     */
    @ResponseBody
    @PostMapping("/select")
    public Result<Pagination<OrderReturnReasonVO>> select(HttpServletRequest request, @RequestBody Pagination<OrderReturnReasonVO> pagination) throws Exception {
        return Result.ok(orderReturnReasonService.selectPagination(pagination));
    }

    /**
     * 功能描述：保存或者修改退货原因
     *
     * @param request 请求
     * @param dto     退货原因
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/save")
    public Result<Object> save(HttpServletRequest request, @RequestBody @Validated OrderReturnReasonDTO dto) throws Exception {
        return Result.saveOrUpdate(orderReturnReasonService.saveOrUpdate(dto));
    }

    /**
     * 功能描述：根据ID获取退货原因
     *
     * @param request 请求
     * @param orderReturnReasonId  退货原因ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/info")
    public Result<OrderReturnReasonVO> info(HttpServletRequest request, @RequestParam(name = "orderReturnReasonId") Long orderReturnReasonId) throws Exception {
        return Result.ok(orderReturnReasonService.selectById(orderReturnReasonId));
    }

    /**
     * 功能描述：删除退货原因
     *
     * @param request 请求
     * @param orderReturnReasonIds 批量删除的退货原因ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/delete")
    public Result<Object> delete(HttpServletRequest request, @RequestParam(name = "orderReturnReasonIds") List<Long> orderReturnReasonIds) {
        return Result.delete(orderReturnReasonService.delete(orderReturnReasonIds));
    }

}
